#!/bin/sh

mode=`uci get powertools.@system[0].mode`
#[ "$mode" != "1" ] && return
sleep 10
while [ 1 ]; do
#	iwconfig_wlan1=`iwconfig wlan1 | grep Frequency`
	route_log=`route | grep wlan1`
	
	if [ -z "$route_log" ]; then
	{
		killall -9 wpa_supplicant >/dev/null 2>&1
		iw wlan0 set channel 1
		sleep 30
		continue

	}
	fi
	wlan1_channel=`iwlist wlan1 channel | grep "Current Frequency:" | awk '{print $5}' | awk -F')' '{print $1}'`

	wlan0_channel=`iwlist wlan0 channel | grep "Current Frequency:" | awk '{print $5}' | awk -F')' '{print $1}'`

	
	if [ $wlan0_channel -ne $wlan1_channel ] && [ -n "$wlan1_channel" ] && [ -n "$route_log" ]; then
		iw wlan0 set channel $wlan1_channel
	fi
	
	sleep 30
done
